package GUI;

import java.awt.Dimension;
import java.awt.Font;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.JLabel;
import javax.swing.JPanel;

public class Clock extends JPanel{
	
	JLabel currenttime;
	int minute, second;
	Timer CountdownTimer;
	
	 Font bigFont = new Font("serif", Font.BOLD, 28);
	
	 public Clock(){
	   this.setPreferredSize(new Dimension(50, 20));
	   minute = 5;
	   second = 0;
	   currenttime = new JLabel(String.valueOf(minute) + ":" + String.valueOf(second));
	   this.add(currenttime);
	   CountdownTimer = new Timer();
	   CountdownTimer.schedule(new Countdown(this), 0, 1000);
	}
	 	   
	public void Reset(){
	   CountdownTimer.cancel();
	   minute = 5;
	   second = 0;
	   CountdownTimer.schedule(new Countdown(this), 1000);
	}
	 	   
	class Countdown extends TimerTask{
	   
		Clock myclock;
		public Countdown(Clock _myclock){
	       myclock = _myclock;
	   }
		public void run(){
	     if (second == 0) {
	 	   second = 59;
	 	   minute --;
	    }
	 	else second--;
	 	currenttime.setText(String.valueOf(minute) + ":" + String.valueOf(second));
	 	myclock.repaint();  
	 	if (minute == 0)
	 	CountdownTimer.cancel();
	 }
	}
 }

